package editorview.views.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import editorview.views.EditorsTreeViewer;

public class CloseAction extends Action {

  private EditorsTreeViewer editorsTreeViewer;

  public CloseAction(EditorsTreeViewer editorsTreeViewer) {
    this.editorsTreeViewer = editorsTreeViewer;
    Image image = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_DELETE);
    ImageDescriptor imageDescriptor = ImageDescriptor.createFromImage(image);
    setImageDescriptor(imageDescriptor);
  }

  @Override
  public void run() {
    IEditorReference[] selectedEditors = editorsTreeViewer.getSelectedEditors();
    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditors(selectedEditors, true);
  }
}
